package com.zuocheng.librarycar;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

public class MineActivity extends Activity {

    private ArrayList<String> mDatas = new ArrayList<>();

    private void generateDatas() {
//        for (int i = 1; i <= 100; i++) {
//            mDatas.add("第 " + i + " 个item");
//        }

        mDatas.add("清除缓存");
        mDatas.add("用户协议");
        mDatas.add("关于我们");
        mDatas.add("当前版本");
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mine);
        initTitle();
        setAndroidNativeLightStatusBar(this,true);


        generateDatas();
        RecyclerView mRv = findViewById(R.id.linearRv);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);//线性布局
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRv.setLayoutManager(linearLayoutManager);

        MineRecyclerView adapter = new MineRecyclerView(this, mDatas);
        mRv.setAdapter(adapter);


        TextView loginBtn = (TextView)findViewById(R.id.tv_login);
        loginBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                System.out.println("-------");
                finish();
                SharedPreferences sp = getSharedPreferences("yuecun", Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = sp.edit();
                editor.putString("Authorization","");
                editor.commit();
                LoginActivity.start(getApplicationContext());

            }
        });
    }

    public static void start(Context context) {
        Intent intent = new Intent(context,MineActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    public void initTitle() {
        OverAllTitleBar rlTitle = findViewById(R.id.rl_title);
        rlTitle.tvTitle.setText("个人中心");
        rlTitle.ivBack.setVisibility(View.VISIBLE);
        rlTitle.ivBack.setOnClickListener(v -> {
            finish();
        });
    }
    //设置状态栏字体颜色
    private static void setAndroidNativeLightStatusBar(Activity activity, boolean dark) {
        View decor = activity.getWindow().getDecorView();
        if (dark) {
            decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        } else {
            decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        }
    }
}
